﻿using MediatR;
using SystemWFH.API.Application.Command.ProductionPlanningCommand;
using SystemWFH.Infrstructer.Impl;
using SystemWFH.Infrstructer.Interface;

namespace SystemWFH.API.Application.CommandHandlers.ProductionPlanningCommandHandler
{
    public class ProductionPlanningUpdateCommandHandler : IRequestHandler<ProductionPlanningUpdateCommand, int>
    {
        private readonly IProductionPlanningRepository productionPlanning;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="productionPlanning">上下文对象</param>
        public ProductionPlanningUpdateCommandHandler(IProductionPlanningRepository productionPlanning)
        {
            this.productionPlanning = productionPlanning;
        }

        public async Task<int> Handle(ProductionPlanningUpdateCommand request, CancellationToken cancellationToken)
        {
            var shijian = request.scheduledEndTime.ToUniversalTime();
            var shijian1 = request.DeliveryDate.ToUniversalTime();
            var shijian2 = request.actualStartTime.ToUniversalTime();
            var shijian3 = request.actualEndTime.ToUniversalTime();
            var shijian4 = request.planTheStartTime.ToUniversalTime();
            return await productionPlanning.UpdateAsync(new Domain.ProductionPlanning
            {
                productionId=request.productionId,
                plannedProduction=request.plannedProduction,
                planTheStartTime=shijian4,
                productionSerialNumber=request.productionSerialNumber,
                productionStatus=request.productionStatus,
                MyProperty = request.MyProperty,
                theFinishedProduct=request.theFinishedProduct,
                theProductionPlanNumber=request.theProductionPlanNumber,
                actualEndTime=shijian3,
                actualStartTime=shijian2,
                workShop=request.workShop,
                numberReportedJobs=request.numberReportedJobs,
                DeliveryDate=shijian1,
                orderNumber=request.orderNumber,
                routing=request.routing,
                scheduledEndTime=shijian,
                specificationsAndModels=request.specificationsAndModels,
                IsDelete=request.IsDelete,
                UpdateName= "王飞红",
                UpdateTime = DateTime.Now.ToUniversalTime(),
                AddName ="王飞红",
                AddTime= DateTime.Now.ToUniversalTime(),
            });
        }
    }
}
